<!DOCTYPE html>
<html>
<head lang="en">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" >
    <title>业务日志</title>
    [#include "../../common.ftl"]
    [@includeCommonJS /]
</head>
<body>
<div id="mainScroll">

<div class="content">
    <div class="panel" >
    <div class="panel-heading">业务日志管理</div>
    <div class="panel-body">
        <!-- Tables -->
        <form name="bizLogSearchForm" id="bizLogSearchForm" action="/logger/bizLog/search" method="post">
            <input type="hidden" name="collapse" value="${collapse!}">
            <div class="row">
                <div class="col-lg-3 col-md-3 col-sm-3">
                    <div class="input-group search">
                        <input type="text" class="form-control" id="content" name="content" maxlength="50" value="${content?html}" placeholder="输入内容模糊查询">
                      <span class="input-group-btn">
                            <button class="btn" onclick="searchBizLog();" style="height: 30px;"><span class="ti-search" ></span></button>
                      </span>
                    </div><!-- /input-group -->
                </div>
                <div class="col-lg-6 col-md-5 col-sm-4">
                    <a class="font-12 btn btn-link" data-toggle="collapse" href="#collapse_searchMore" aria-expanded="false" aria-controls="collapseExample">更多筛选条件<span class="ti-angle-double-down"></span></a>
                </div>
                <div class="col-lg-3 col-md-4 col-sm-5 text-right">
                    <!-- 下拉按钮 -->
                    <div class="dropdown pull-right">
                        <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="false">
                            <span class="ti-settings"></span>&nbsp;批量操作
                            <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
                            <li role="presentation"><a role="menuitem" tabindex="-1" style="cursor: pointer" onclick="batchDelete()"><span class="ti-trash"></span>&nbsp;删除</a></li>
                            <li role="presentation"><a role="menuitem" tabindex="-1" style="cursor: pointer" onclick="batchOpen('true')"><span class="ti-stamp"></span>&nbsp;设置可见</a></li>
                            <li role="presentation"><a role="menuitem" tabindex="-1" style="cursor: pointer" onclick="batchOpen('false')"><span class="ti-stamp"></span>&nbsp;设置不可见</a></li>
                            <li role="presentation"><a role="menuitem" tabindex="-1" style="cursor: pointer" onclick="exportBizLog()"><span class="ti-export"></span>&nbsp;导出</a></li>
                        </ul>
                    </div>
                    <button class="btn btn-blue" type="button" onclick="add();"><span class="ti-plus"></span>&nbsp;新增</button>&nbsp;&nbsp;
                </div>
            </div>
            <div class="collapse" id="collapse_searchMore">
                <div class="form-horizontal well" role="form">
                    <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
                        <div class="form-group">
                            <label for="companyId" class="control-label col-lg-4 col-md-6 col-sm-5 text-left">企业：</label>
                            <div class="col-lg-8 col-md-6 col-sm-7">
                                <input type="text" id="companyId" name="companyId" maxlength="50" value="${companyId?html}" class="form-control" placeholder="">
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
                        <div class="form-group">
                            <label for="applicationId" class="control-label col-lg-4 col-md-6 col-sm-5 text-left">应用：</label>
                            <div class="col-lg-8 col-md-6 col-sm-7">
                                <input type="text" id="applicationId" name="applicationId" maxlength="50" value="${applicationId?html}" class="form-control" placeholder="">
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
                        <div class="form-group">
                            <label for="moduleId" class="control-label col-lg-4 col-md-6 col-sm-5 text-left">模块：</label>
                            <div class="col-lg-8 col-md-6 col-sm-7">
                                <input type="text" id="moduleId" name="moduleId" maxlength="50" value="${moduleId?html}" class="form-control" placeholder="">
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
                        <div class="form-group">
                            <label for="operatorType" class="control-label col-lg-4 col-md-6 col-sm-5 text-left">日志类型：</label>
                            <div class="col-lg-8 col-md-6 col-sm-7">
                                <select id="operatorType" name="operatorType" style="width:100%;" class="select2">
                                    <option value="" selected>全部</option>
                                    <option value="0" [#if operatorType="0"]selected[/#if]>用户</option>
                                    <option value="1" [#if operatorType="1"]selected[/#if]>系统</option>
                                    <option value="2" [#if operatorType="2"]selected[/#if]>任务</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
                        <div class="form-group">
                            <label for="visible" class="control-label col-lg-4 col-md-6 col-sm-5 text-left">是否可见：</label>
                            <div class="col-lg-8 col-md-6 col-sm-7" >
                                <select id="visible" name="visible" style="width:100%;" class="select2">
                                    <option value="" selected>全部</option>
                                    <option value="1" [#if visible="1"]selected[/#if]>是</option>
                                    <option value="0" [#if visible="0"]selected[/#if]>否</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-6 col-md-6">
                        <div class="form-group">
                            <label for="schoolTime" class="control-label col-sm-3 text-left">操作时间：</label>
                            <div class="col-sm-9">
                                <table id="schoolTime" width="100%" cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td width="47%">
                                            <div class="has-feedback">
                                                <input class="form-control" id="datetimeStart" name="datetimeStart" value="${datetimeStart}" type="text" placeholder="">
                                                <span class="form-control-feedback ti-calendar" aria-hidden="true" style="top: 8px"></span>
                                            </div>
                                        </td>
                                        <td align="center" valign="top">
                                            <div class="blank-5"></div>
                                            至
                                        </td>
                                        <td width="47%">
                                            <div class="has-feedback">
                                                <input class="form-control" id="datetimeEnd" name="datetimeEnd" type="text" value="${datetimeEnd}" placeholder="">
                                                <span class="form-control-feedback ti-calendar" aria-hidden="true" style="top: 8px"></span>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
                        <div class="form-group">
                            <label class="control-label col-lg-4 col-md-6 col-sm-5 text-left">&nbsp;</label>

                            <div class="col-lg-8 col-md-6 col-sm-7">
                                <button onclick="searchBizLog();" class="btn btn-blue">开始筛选</button>
                            </div>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </div>
        </form>
        <div class="">
            <table class="table table-hover table-bordered">
                <thead>
                <tr>
                    <th><input type="checkbox" name="ckAll" id="ckAll" onclick="checkboxAll();"></th>
                    <th>序号</th>
                    <th>企业</th>
                    <th>应用</th>
                    <th>模块</th>
                    <th>类型</th>
                    <th>内容</th>
                    <th>IP地址</th>
                    <th>是否可见</th>
                    <th>创建时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                [#if bizLogs?size == 0]
                <tr>
                    <td colspan="12" style="vertical-align:middle;">
                        <h4 class="text-center"><small>没有找到相关数据</small></h4>
                    </td>
                </tr>
                [/#if]
                [#list bizLogs as bizLog]
                <tr>
                    <td>
                        <input type="checkbox" name="ckSub" value="${bizLog.id}">
                    </td>
                    <td>${pageFirst+bizLog_index}</td>
                    <td>${bizLog.companyId}</td>
                    <td>${bizLog.applicationId}</td>
                    <td>${bizLog.moduleId}</td>
                    <td>
                        [#if bizLog.operatorType == "0"]
                            用户
                        [#elseif bizLog.operatorType == "1"]
                            系统
                        [#else]
                            任务
                        [/#if]
                    </td>
                    <td>${bizLog.content?html}</td>
                    <td>${bizLog.ipAddress}</td>
                    <td>${(bizLog.visible)?string("是","否")}</td>
                    <td>${bizLog.operateDate}</td>
                    <td>
                        <button class="btn btn-link pull-left" data-toggle="tooltip" data-placement="top" title="" data-original-title="修改" onclick="edit('${bizLog.id}');"><span class="ti-pencil-alt"></span></button>
                        <button class="btn btn-link pull-left" data-toggle="tooltip" data-placement="top" title="删除" onclick="deleteBizLog('${bizLog.id}');"><span class="ti-trash"></span></button>
                    </td>
                </tr>
                [/#list]
                </tbody>
            </table>
        </div>

        <div class="blank-10"></div>
        <div id="pageDiv" style="text-align: right">
            <ul id="pageLimit"></ul>
        </div>

    </div>
    </div>

</div>
</div>

<form name="bizLogListForm" id="bizLogListForm" action="" method="post"></form>

</body>
</html>
<script type="text/javascript">

    $(function(){
        //带搜索下拉
        $(".select2").select2({
            minimumResultsForSearch: Infinity
        });

        // icheck
        $("input[name='ckAll'],input[name='ckSub']").iCheck({
            checkboxClass: "icheckbox_minimal-blue",
            radioClass: "iradio_minimal-blue",
            increaseArea: "20%" // optional
        });

        //黑色工具提示
        $('button[data-toggle="tooltip"]').tooltip();

        $("#mainScroll").mCustomScrollbar({theme:"dark-thin",scrollInertia:300});
        $.mCustomScrollbar.defaults.axis="yx"; //默认支持横向和纵向滚动条
        $("#collapse_searchMore").collapse("${collapse!}");

        //日期时间选择器
        $("#datetimeStart").datetimepicker({
            format: "yyyy-mm-dd",
            autoclose: true,
            minView: "month",
            maxView: "decade",
            todayBtn: true,
            pickerPosition: "bottom-left"
        }).on("click",function(ev){
            $("#datetimeStart").datetimepicker("setEndDate", $("#datetimeEnd").val());
        });
        $("#datetimeEnd").datetimepicker({
            format: "yyyy-mm-dd",
            autoclose: true,
            minView: "month",
            maxView: "decade",
            todayBtn: true,
            pickerPosition: "bottom-left"
        }).on("click", function (ev) {
            $("#datetimeEnd").datetimepicker("setStartDate", $("#datetimeStart").val());
        });


    });

    function batchOpen(status) {
        var bizLogIds = "";
        $('input[name="ckSub"]:checked').each(function(){
            bizLogIds = bizLogIds + $(this).val() + ",";
        });
        if(bizLogIds == "") {
            BootstrapDialog.alert({title:"信息",message:"请选择一条或多条记录！",buttonLabel:"确定"});
            return;
        }
        var form = document.bizLogListForm;
        form.action = "/logger/bizLog/batchOpen?bizLogIds="+bizLogIds+"&visible="+status;
        form.submit();
    }

    function exportBizLog() {
        var searchStr = $("#bizLogSearchForm").serialize();
        var bizLogIds = getSelectIds("ckSub");
        searchStr = searchStr + "&bizLogIds=" + bizLogIds;
        var form = document.bizLogListForm;
        form.action = "/logger/bizLog/export?"+searchStr;
        form.submit();
    }

    function edit(id) {
        location.href ="/logger/bizLog/edit?bizLogId="+id;
    }

    function add() {
        location.href ="/logger/bizLog/edit";
    }

    function batchDelete() {
        var bizLogIds = "";
        $('input[name="ckSub"]:checked').each(function(){
            bizLogIds = bizLogIds + $(this).val() + ",";
        });
        if(bizLogIds == "") {
            BootstrapDialog.alert({title:"信息",message:"请选择一条或多条记录！",buttonLabel:"确定"});
            return;
        }
        BootstrapDialog.confirm({
            title:'信息',
            message:'确认删除选中的记录吗？',
            btnCancelLabel: "取消",
            btnOKLabel: "确定",
            callback: function(result) {
                if (result) {
                    $.ajax({
                        type: "POST",
                        url: "/logger/bizLog/delete",
                        data: {"bizLogIds": bizLogIds},
                        success: function (data) {
                            if (data == "SUCCESS") {
                                window.location.href = '/logger/bizLog/search';
                            } else if (data == "FAILED") {
                                BootstrapDialog.alert({title: "信息", message: "删除失败！", buttonLabel: "确定"});
                            }
                        }
                    });
                } else {
                    return;
                }
            }
        });
    }

    function deleteBizLog(bizLogId) {
        BootstrapDialog.confirm({
            title:'信息',
            message:'确认删除当前记录吗？',
            btnCancelLabel: "取消",
            btnOKLabel: "确定",
            callback: function(result) {
                if (result) {
                    $.ajax({
                        dataType: "html",
                        type: "POST",
                        url: "/logger/bizLog/delete",
                        data: {"bizLogId": bizLogId},
                        success: function (data) {
                            if (data == "SUCCESS") {
                            } else if (data == "FAILED") {
                                BootstrapDialog.alert({title: "信息", message: "删除失败！", buttonLabel: "确定"});
                                return;
                            }
                            window.location.href = '/logger/bizLog/search';
                        }
                    });
                } else {
                    return;
                }
            }
        });
    }

    function searchBizLog() {
        var collapse = $("#collapse_searchMore").is(":hidden") ? "hide" : "show";
        $("input[name='collapse']").val(collapse);
        $("#bizLogSearchForm").submit();
    }

    // iCheck的全选与反选
    $("#ckAll").on("ifChecked", function(event){
        $("input:checkbox[name='ckSub']").iCheck("check");
    });
    $("#ckAll").on("ifUnchecked", function(event){
        $("input:checkbox[name='ckSub']").iCheck("uncheck");
    });

    // 分页信息
    var totalPages = ${(openPage.totalPages)!};
    var total = ${(openPage.total)!};
    var pageNo = ${(openPage.pageNo)!};
    var pageSize = ${(openPage.pageSize)!};
    if(totalPages > 1) {
        pageLimit(total, pageNo, pageSize, totalPages);
    }

    function pageLimit(total, currentPage, pageSize, totalPages) {
        var options = {
            currentPage: currentPage,
            totalPages: totalPages,
            numberOfPages: 5,
            bootstrapMajorVersion: 3,
            itemTexts: function (type, page, current) {
                switch (type) {
                    case "first":
                        return "首页";
                    case "prev":
                        return "上一页";
                    case "next":
                        return "下一页";
                    case "last":
                        return "尾页";
                    case "page":
                        return page;
                }
            },
            tooltipTitles: function (type, page, current) {
                switch (type) {
                    case "first":
                        return "首页";
                    case "prev":
                        return "上一页";
                    case "next":
                        return "下一页";
                    case "last":
                        return "尾页";
                    case "page":
                        return "第"+page+"页";
                }
            },
            onPageClicked: function (e, originalEvent, type, page) {
                var searchStr = $("#bizLogSearchForm").serialize();
                var form = document.bizLogSearchForm;
                var collapse = $("#collapse_searchMore").is(":hidden") ? "hide" : "show";
                $("input[name='collapse']").val(collapse);
                form.action = "/logger/bizLog/search?searchStr&pageNo="+page+"&pageSize="+pageSize;
                form.submit();
            }
        }

        $("#pageLimit").bootstrapPaginator(options);
    }


</script>